﻿using Microsoft.AspNetCore.Mvc;
using NFine.Data.Dto.WeixinManage;
using NFine.Service.WeixinManage;
using NFine.Util;
using NFine.Web.Controllers;

namespace NFine.Web.Areas.WeiXinManage.Controllers
{
    [Area("WeiXinManage")]
    public class WxAccountController : BaseController
    {
        WxAccountService wxAccountService = new WxAccountService();
        //protected readonly Rabbit.WeiXin.MP.Api.ICommonService CommonService;

        public override IActionResult Index()
        {
            //OperatorModel operatorModel = OperatorProvider.Provider.GetOperator();
            //operatorModel.AccountModel = new Rabbit.WeiXin.MP.Api.AccountModel
            //{
            //    AppId = operatorModel.WxAccountModel.AppId,
            //    AppSecret = operatorModel.WxAccountModel.AppSecret,
            //    GetAccessToken = CommonService.GetAccessToken()
            //};

            return View();
        }
        [HttpGet]
        public ActionResult GetGridJson(string keyword)
        {
            var data = new
            {
                rows = wxAccountService.GetList(keyword)
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        public ActionResult GetFormJson(string keyValue)
        {
            var data = wxAccountService.GetForm(keyValue);
            return Content(data.ToJson());
        }

        [HttpPost]
        public ActionResult SubmitForm(WxAccountInputDto wxAccountInputDto, string keyValue)
        {
            wxAccountService.SubmitForm(wxAccountInputDto, keyValue);
            return Success("操作成功。");
        }

        [HttpPost]
        public ActionResult DeleteForm(string keyValue)
        {
            wxAccountService.DeleteForm(keyValue);
            return Success("操作成功。");
        }

        [HttpPost]
        public ActionResult EnabledForm(string keyValue)
        {
            wxAccountService.EnabledForm(keyValue);
            return Success("账户启用成功。");
        }

        [HttpPost]
        public ActionResult DisabledForm(string keyValue)
        {
            wxAccountService.DisabledForm(keyValue);
            return Success("账户禁用成功。");
        }
    }
}